<template>
  <div>
    <common-head title="用户登录" />
    <div class="wrap">
      <h2>请先登录</h2>
      <van-form @submit="onSubmit">
        <van-field style="margin:50px 10px;" v-model="user.userName" name="用户名" label="用户名" placeholder="用户名" :rules="[ { required: true, message: '请填写用户名' } ]" />
        <van-field style="margin:50px 10px;" v-model="user.pwd" type="password" name="密码" label="密码" placeholder="密码" :rules="[{ required: true, message: '请填写密码' }]" />
        <div style="margin: 80px 20px;">
          <van-button round block type="info" native-type="submit">立即登录</van-button>
        </div>
      </van-form>
    </div>
    <my-tabbar />
  </div>
</template>
<script>
import MyTabbar from '@components/MyTabbar'
import CommonHead from '@components/CommonHead'
import { Toast } from 'vant'
export default {
  data () {
    return {
      user: {
        userName: '',
        pwd: ''
      }
    }
  },
  methods: {
    onSubmit () {
      // 提交表单事件
      setTimeout(() => {
        const authToken = 'feihfioge394t598trhfcis'
        const userInfo = {
          nickName: '小萌新',
          avatar: 'http://inews.gtimg.com/newsapp_bt/0/13107498541/1000'
        }
        localStorage.setItem('auth_token', authToken)
        localStorage.setItem('userInfo', JSON.stringify(userInfo))
        Toast('登录成功')
        if (this.$route.query.from) {
          this.$router.replace(this.$route.query.from)
        } else {
          this.$router.replace('/home')
        }
      })
    }
  },
  components: {
    MyTabbar,
    CommonHead
  }
}
</script>
<style lang="scss" scoped>
.wrap{
  margin-top: 46px;
  background: #fff;
  h2{
    height: 60px;
    font-size: 30px;
    line-height: 80px;
    text-align: center;
    margin: 0px 0 50px;
  }
}
</style>
